package com.itboye.ihomebank.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
/**
 * 保存钥匙（数据库）
 *
 */
public class DBOpenHelper extends SQLiteOpenHelper {
	
	public static final String DB_PATH = "/data"
			+ Environment.getDataDirectory().getAbsolutePath() + "/"
			+ "com.itboye.ihomebank"; // 存放路径
	
	public static final String KEYDB="mykey.db";
	
	public DBOpenHelper(Context context) {
		super(context, KEYDB, null, 1);
	}
	//数据库第一次创建时候调用
	@Override
	public void onCreate(SQLiteDatabase db) {
		//调用execSQL()方法执行建表语句(备份钥匙)
		db.execSQL("create table key(id integer primary key autoincrement, lock_id varchar(50), key_id varchar(50), lock_mac varchar(50), lock_alias varchar(50))");
		
		//调用execSQL()方法执行建表语句我的钥匙列表)
		db.execSQL("create table mykey(id integer primary key autoincrement, lock_id varchar(50), key_id varchar(50), start varchar(50), end varchar(50), create_time varchar(50), update_time varchar(50), status varchar(50), type varchar(50), lock_alias varchar(50), house_no varchar(50), user_type varchar(50), lock_mac varchar(50), push varchar(50), key_status varchar(50), is_new varchar(50))");

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}
	/**
	 * 删除数据库
	 * @param context
	 * @return
	 */
	public boolean deleteDatabase(Context context) {
		return context.deleteDatabase(KEYDB);
	}
}
